import React from 'react';
import { RequestConfig } from 'umi';
import { routes } from './router';
import {
  BasicLayoutProps,
  Settings as LayoutSettings,
} from '@ant-design/pro-layout';
import { createLogger } from 'redux-logger';
import { message } from 'antd';

console.log(process.env);


const newMenuList = (list: any) => {
  return list
}

export const layout = ({
  initialState,
}: {
  initialState: { settings?: LayoutSettings; currentUser?: API.CurrentUser };
}): BasicLayoutProps => {
  return {
    // layout:'mix',
    title: '宏烨找房',
    navTheme: 'dark',
    menuDataRender: () => newMenuList(routes),
    // rightContentRender: () => <RightContent />,
    // footerRender: () => <Footer />,
    // onPageChange: () => {
    //   const { currentUser } = initialState;
    //   const { location } = history;
    //   // 如果没有登录，重定向到 login
    //   if (!currentUser && location.pathname !== '/user/login') {
    //     history.push('/user/login');
    //   }
    // },
    menuHeaderRender: undefined,
    ...initialState?.settings,
  };
};

export const request: RequestConfig = {
  timeout: 1000,
  baseUrl: process.env.umi_ENV_REQUESR_URL,
  errorConfig: {},
  middlewares: [],
  requestInterceptors: [
    (url: string, options: any) => {
      const headers = options.headers
      return {
        url:`${url}`,
        options:{
          ...options,
          headers
        }
      }
    }
  ],
  responseInterceptors: [
    (res)=>{
      console.log(res,'res');
      return res
    }
  ],
};

export const dva = {
  config: {
    onAction: createLogger(),
    onError(e: Error) {
      message.error(e.message, 3);
    },
  },
};